var events = require('events');


//new 一个实例给People 属性
var People = function(){
    this.emitter = new events.EventEmitter(this);
} 

People.prototype.on = function(light,callback){
    this.emitter.on(light,callback);
}

People.prototype.crossRoad = function(light){
    this.emitter.emit("crossRoad",light);
}

var Car =function(){
    this.emitter = new events.EventEmitter(this);
}

Car.prototype.on = function(light,callback){
    this.emitter.on(light,callback);
}

Car.prototype.crossRoad = function(light){
    this.emitter.emit("crossRoad",light);
}

var people = new People();
people.on("crossRoad",function(light){
    console.log(light+ "亮起，行人准备通过");
})

var car = new Car();
car.on("crossRoad",function(light){
    console.log(light + "亮起，车辆准备通过。。。");
})


console.log("焦急地等待红灯中。。。。。。");

setTimeout(function(){
    var light = "绿灯";
    console.log(light + "突然亮起");
    people.crossRoad(light);
    car.crossRoad(light);
},3000)
